package com.log530_projetfinal;

import java.util.Hashtable;

import java.util.Set;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.drawable.ColorDrawable;
import android.widget.LinearLayout;

public class EcoSystemMap {

	private Hashtable<String, Vegetale> listVegetales = EnsembleVegetale.getListe();
	private Hashtable<String, Herbivore> listHerbivores = EnsembleHerbivore.getListe();
	private Hashtable<String, Carnivore> listCarnivores = EnsembleCarnivore.getListe();

	public void paintMap(Canvas canvas, Paint paint) {
		paintVegetale(canvas, paint);
		paintHerbivore(canvas, paint);
		paintCarnivore(canvas, paint);
	}

	public void paintVegetale(Canvas canvas, Paint paint) {
		RectF ovalBounds;
		Set<String> ks = listVegetales.keySet();
		for (String str : ks) {
			Vegetale vegetale = listVegetales.get(str);
			if (vegetale.vivant) {
				int size = vegetale.size;
				int halfSize = size / 2; // pour centrer le cercle

				if (vegetale.maturite)
					paint.setColor(Color.argb(150, 255, 105, 180));//pink
				else
					paint.setColor(Color.argb(150,0,59,111));//blue

				// FIXME method dans element return rectF instead more clean
				// after
				ovalBounds = new RectF((vegetale.coordo.x - halfSize-2),(vegetale.coordo.y - halfSize-2),(vegetale.coordo.x + halfSize+2),(vegetale.coordo.y + halfSize+2));
				
				canvas.drawOval(ovalBounds, paint);

				int ptVie = vegetale.vie;

				// FIXME change color plante selon ptVie
				//paint.setColor(Color.GREEN);
				if (ptVie <= 500) {
					paint.setColor(Color.argb(200, 0, 255, 0));
				} else if (ptVie > 500 && ptVie <= 1000) {
					paint.setColor(Color.argb(200, 0, 205, 0));
				} else if (ptVie > 1000 && ptVie <= 1500) {
					paint.setColor(Color.argb(200, 0, 155, 0));
				} else if (ptVie > 1500) {
					paint.setColor(Color.argb(200, 0, 105, 0));
				}
				// rectf(xLeft,yTop,xRight, yBottom)
				ovalBounds = new RectF((vegetale.coordo.x - halfSize),(vegetale.coordo.y - halfSize), (vegetale.coordo.x + halfSize),(vegetale.coordo.y + halfSize));
				canvas.drawOval(ovalBounds, paint);
			}
		}
	}

	public void paintHerbivore(Canvas canvas, Paint paint) {
		Set<String> ks = listHerbivores.keySet();
		RectF ovalBound;
		for (String str : ks) {
			Herbivore herbivore = listHerbivores.get(str);
			int size = herbivore.size;
			int halfSize = size / 2;
			int halfYeux = herbivore.yeux / 2;
			int halfNez = herbivore.nez / 2;

			// cercle odorat
			paint.setColor(Color.argb(30, 0, 255, 255));//bleu pale
			ovalBound = new RectF((herbivore.coordo.x - halfNez),(herbivore.coordo.y - halfNez), (herbivore.coordo.x + halfNez),(herbivore.coordo.y + halfNez));
			canvas.drawOval(ovalBound, paint);
			
			// cercle yeux
			paint.setColor(Color.argb(40,255, 200, 0));//orange
			ovalBound = new RectF((herbivore.coordo.x - halfYeux),(herbivore.coordo.y - halfYeux), (herbivore.coordo.x + halfYeux),	(herbivore.coordo.y + halfYeux));
			canvas.drawOval(ovalBound, paint);

			if (herbivore.maturite) {
				paint.setColor(Color.argb(90, 255, 105, 180));//PINK
			} else {
				paint.setColor(Color.argb(90,0,59,111));//blue
			}		
			ovalBound = new RectF((herbivore.coordo.x - halfSize - 2),(herbivore.coordo.y - halfSize - 2), (herbivore.coordo.x + halfSize + 2), (herbivore.coordo.y + halfSize + 2));
			canvas.drawOval(ovalBound, paint);
			
			//System.out.println("Coordo X: "+ herbivore.coordo.x+ " Y: " + herbivore.coordo.y +" halfSize: "+ halfSize);
			paint.setColor(Color.YELLOW);
			ovalBound = new RectF((herbivore.coordo.x - halfSize),(herbivore.coordo.y - halfSize), (herbivore.coordo.x + halfSize), (herbivore.coordo.y + halfSize));
			canvas.drawOval(ovalBound, paint);

		}

	}

	public void paintCarnivore(Canvas canvas, Paint paint){
		Set<String> ks = listCarnivores.keySet();
		RectF ovalBound;
		
		for (String str : ks) {
			Carnivore carnivore = listCarnivores.get(str);
			int size = carnivore.size;
			int halfSize = size / 2;
			int halfYeux = carnivore.yeux / 2;
			int halfNez = carnivore.nez / 2;
			
			// cercle odorat
			paint.setColor(Color.argb(50,0, 255, 255));
			ovalBound = new RectF((carnivore.coordo.x - halfNez), (carnivore.coordo.y - halfNez), (carnivore.coordo.x + halfNez),(carnivore.coordo.y + halfNez));
			canvas.drawOval(ovalBound, paint);

			// cercle yeux
			paint.setColor(Color.argb(50,255, 200, 0));//orange
			ovalBound = new RectF((carnivore.coordo.x - halfYeux), (carnivore.coordo.y - halfYeux),(carnivore.coordo.x + halfYeux), (carnivore.coordo.y + halfYeux));
			canvas.drawOval(ovalBound, paint);
			
			if (carnivore.maturite) {
				paint.setColor(Color.argb(150, 255, 105, 180));//PINK
			} else {
				paint.setColor(Color.argb(90,0,59,111));//blue				
			}
			ovalBound = new RectF((carnivore.coordo.x - halfSize - 2), (carnivore.coordo.y- halfSize - 2), (carnivore.coordo.x + halfSize + 2),  (carnivore.coordo.y + halfSize + 2));
			canvas.drawOval(ovalBound, paint);
			
			paint.setColor(Color.RED);
			ovalBound = new RectF((carnivore.coordo.x - halfSize),(carnivore.coordo.y - halfSize), (carnivore.coordo.x + halfSize), (carnivore.coordo.y + halfSize));
			canvas.drawOval(ovalBound, paint);
		}
	}
}